package com.kfm.base.thread.day01;

public class Demo {

    public static void main(String[] args) {
        System.out.println("main start");

        // 创建 线程对象
        MyThread t1 = new MyThread("线程1：");
        MyThread t2 = new MyThread("线程2：");
//        System.out.println(t1.getPriority());
//        Thread thread = Thread.currentThread(); // 获取当前正在执行的线程
//        System.out.println(thread.getPriority()); // 线程优先级
//        t1.run(); // 方法调用

        t1.start(); // 启动线程
        t2.start();


//        System.out.println(thread.getName()); // main

//        try {
//            Thread.sleep(1); // 当前线程休眠 1 毫秒
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }

        for (int i = 0; i < 300; i++) {
            System.out.println("main end" + i);
        }
    }
}

// 线程类
class MyThread extends Thread {
    int count = 0;

    public MyThread(){}

    public MyThread(String name){
        super(name);
    }

    @Override
    public void run() {
        for (int i = 0; i < 30; i++) {
            Thread thread = Thread.currentThread(); // 获取当前正在执行的线程
            String name = thread.getName(); // 线程名称


            System.out.println(getName() + " 自定义线程的 run()" + i);
        }
    }
}